<?php 
	session_start();
	require 'auth.php';
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>聚合物产品工程科技创新团队药品管理软件|药品详情</title>
<link rel="stylesheet" type="text/css" href="reagentdb_data.css" />
</head>

<body>
<script type="text/javascript">

function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {alert(alerttxt);return false}
  else {return true}
  }
}

function validate_form(thisform)
{
with (thisform)
  {
  	if (validate_required(syr,"请输入使用人")==false)
    	{syr.focus();return false}
  	if (validate_required(shiyongl,"请输入使用量")==false)
    	{shiyongl.focus();return false}
	if (validate_required(syrq,"请输入使用日期")==false)
    	{syrq.focus();return false}
	if (validate_required(shengyul,"请输入剩余量")==false)
    	{shengyul.focus();return false}
 }
}
</script>
<div class="header">
  	<img src="ypglhead.png" width="800" height="120" alt="标题" />
  </div>
<div class="content">

<table border="1" cellspacing="0" cellpadding="0" id="tables">
  <?php
  	require "connectdb.php";
	$result = mysql_query("SELECT * FROM reagent_data where id='".$_GET['id']."'");
	$row = mysql_fetch_array($result);
  ?>
  
  <tr>
    <td width="284" colspan="3" valign="top"><p>药品名称： <?php echo $row['ypmc']?> <br />
      领用量： <?php echo $row['lyl']?><br />
      生产日期： <?php echo $row['scrq']?> <br />
      保质期： <?php echo $row['bzq']?> <br />
      存放地点： <?php echo $row['cfd']?> <br />
      领用人： <?php echo $row['lyr']?> </p></td>
    <td width="284" colspan="3" valign="top"><p>领用日期： <?php echo $row['lyrq']?> <br />
      规格： <?php echo $row['gg']?> <br />
      生产商： <?php echo $row['scs']?> <br />
      国别： <?php echo $row['gb']?> <br />
      供货商： <?php echo $row['ghs']?> <br />
      核销日期： <?php echo $row['hxrq']?> </p></td>
  </tr>
  <tr>
    <td width="568" colspan="6" valign="top"><p align="center">使用记录 </p></td>
  </tr>
  <tr>
    <td width="568" colspan="6" valign="top"><p><strong><u><a href="#add">新增+</a></u></strong></p></td>

  </tr>
  <tr>
    <td width="114" valign="top"><p>序号 </p></td>
    <td width="114" valign="top"><p>使用人 </p></td>
    <td width="114" valign="top"><p>使用量 </p></td>
    <td width="114" valign="top"><p>使用日期 </p></td>
    <td width="114" valign="top"><p>剩余量 </p></td>
  </tr>
  
  	<?php
	if($_POST['syr']!=''&&$_POST['shiyongl']!=''&&$_POST['syrq']!=''&&$_POST['shengyul']!='')
	$addflag=mysql_query("INSERT INTO reagent_record (id, syr, shiyongl, syrq, shengyul) VALUES ('". $_GET['id']. "', '" .$_POST['syr']."', '".$_POST['shiyongl']."', '".$_POST['syrq']."', '". $_POST['shengyul'] ."')");
	$query = "SELECT * FROM reagent_record where id='".$_GET['id']."'";
  	$result = mysql_query($query);
	$xuhao=1;
	while($row = mysql_fetch_array($result)){
		echo "<tr>";
		echo "<td width=\"114\" valign=\"top\">".$xuhao."</td>";
		echo "<td width=\"114\" valign=\"top\">".$row['syr']."</td>";
		echo "<td width=\"114\" valign=\"top\">".$row['shiyongl']."</td>";
		echo "<td width=\"114\" valign=\"top\">".$row['syrq']."</td>";
		echo "<td width=\"114\" valign=\"top\">".$row['shengyul']."</td>";
		$xuhao=$xuhao+1;
		echo "</tr>";
	}
	$result=mysql_query($query);
	$xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
	$xml.="<root>";
	$counter=1;
	while($row=mysql_fetch_array($result)){
		$xml.="<row>";
		$xml.= "<序号>".$counter."</序号>";
		$xml.= "<使用人>".$row['syr']."</使用人>";
		$xml.= "<使用量>".$row['shiyongl']."</使用量>";
		$xml.= "<使用日期>".$row['syrq']."</使用日期>";
		$xml.= "<剩余量>".$row['shengyul']."</剩余量>";
		$xml.="</row>";
		$counter=$counter+1;
	}
	$xml.="</root>";
	unlink("导出2.xml");
	$file=fopen("导出2.xml","w");
	fwrite($file,$xml);
	fclose($file);
	?>
     <a id="add"></a>
     <form action=<?php echo "'detail.php?id=" . $_GET['id'] . "'"; ?> onsubmit="return validate_form(this)" method="post">
     <tr>
     <td width="114" valign="top">新增</td>
     <td width="114" valign="top"> <input type="text" name="syr" size="30"></td>
     <td width="114" valign="top"> <input type="text" name="shiyongl" size="30"></td>
     <td width="114" valign="top"> <input type="text" name="syrq" size="30"></td>
     <td width="114" valign="top"> <input type="text" name="shengyul" size="30"></td>
     </tr>
     <tr><td>
     <input type="submit" value="提交"> 
     </td></tr>
     </form>
  </tr>
</table>
<p><a id="logout" href="logout.php">登出</a></p>
<p><a href="导出2.xml" target="_blank">EXCEL导出（请使用右键->目标另存为）</a></p>
<p>
  <?php require "back.php";?>
</p>
</div>
</body>
</html>